package 笔试.秋招2023.同盾科技;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();//总个数
        int root = sc.nextInt();
        int [][] tree = new int[count][3];
        for (int i=0;i<count;i++) {
            tree[i][0] = sc.nextInt();
            tree[i][1] = sc.nextInt();//L
            tree[i][2] = sc.nextInt();//R
        }
        int lookFor = sc.nextInt();

        for (int i=0;i<count;i++) {
            if(lookFor==tree[i][0]){
                System.out.println(tree[i][2]);
                return;
            }
        }
        System.out.println(0);
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}